package ToYesterday.Day18_insertBSTN;


import org.junit.Test;

class TreeNode {
    int val;
    TreeNode left;
    TreeNode right;
    TreeNode() {}
    TreeNode(int val) { this.val = val; }
    TreeNode(int val, TreeNode left, TreeNode right) {
        this.val = val;
        this.left = left;
        this.right = right;
    }
}
public class Solution {
    TreeNode node;
    public void init(){
        node = new TreeNode(4);
        node.left=new TreeNode(2);
        node.right=new TreeNode(7);
        node.left.left = new TreeNode(1);
        node.left.right = new TreeNode(3);
    }
    public TreeNode insertIntoBST(TreeNode root, int val) {
        if (root==null)return new TreeNode(val);

        if (val< root.val){
            root.left=insertIntoBST(root.left,val);
        }
        if (val> root.val){
            root.right=insertIntoBST(root.right,val);
        }
        return root;
    }
    @Test
    public void TestNode(){
        init();
        TreeNode newnode = insertIntoBST(node,5);
        System.out.println(newnode.right.left.val);
    }

}
